﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WpfApp1
{
    class Service
    {
        private string main_url = "https://hursan.hamdam.biz";
        //private string signature = "5e9cc99545dbee80f137f63435e08cf45e2d3c63a531da293b67c57ea9e42563";
        private string resturant_id = "";
        string secret = "";

        SQLiteHelper sqlite = new SQLiteHelper();
        

        public Service()
        {
            string lang = sqlite.getValue("select value from sys_config where name='lang'", "value");
            resturant_id = sqlite.getValue("select value from sys_config where name='restuarant_id' and lang='" + lang + "'", "value");
            secret = sqlite.getValue("select value from sys_config where name='restuarant_key' and lang='" + lang + "'", "value");
        }


        private string getTimeStamp()
        {
            DateTime timeStamp = new DateTime(1970, 1, 1);  //得到1970年的时间戳
            long currenttimemillis = (DateTime.UtcNow.Ticks - timeStamp.Ticks) / 10000000;  //注意这里有时区问题，用now就要减掉8个小时
            
            string time = currenttimemillis.ToString();// "123456";

            return time;
        }


        public JObject getJSON(string signature, string url)//传入网址
        {
            JObject jo = new JObject();
            string resultstring = "";
            Encoding encoding = Encoding.UTF8;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);//这里的url指要获取的数据网址
            request.Method = "GET";
            request.Accept = "text/html, application/xhtml+xml, */*";
            request.ContentType = "application/json";
            request.Headers["signature"] = signature;
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    resultstring = reader.ReadToEnd();
                }
            }
            catch
            {
              //  MessageBox.Show("远程服务器连接失败");

                return jo;
            }
            // MessageBox.Show(resultstring);
            try
            {
                jo = (JObject)JsonConvert.DeserializeObject(resultstring);
            }
            catch
            {

            }

            return jo;

        }

        public JObject postJSON(string signature, string url,string postDataStr)//传入网址
        {
            JObject jo = new JObject();
            string resultstring = "";
            Encoding encoding = Encoding.UTF8;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);//这里的url指要获取的数据网址
            request.Method = "Post";
            //request.Accept = "text/html, application/xhtml+xml, */*";
            request.ContentType = "application/x-www-form-urlencoded" ;
           // request.ContentType = "application/json";
            request.Headers["signature"] = signature;

            byte[] byte1 = encoding.GetBytes(postDataStr);
            request.ContentLength = byte1.Length;

            try
            {
                Stream newStream = request.GetRequestStream();
                 newStream.Write(byte1, 0, byte1.Length);

               
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
               

                StreamReader reader = new StreamReader(response.GetResponseStream(), encoding);
                resultstring = reader.ReadToEnd();


                 
            }
            catch
            {
                

                return jo;
            }
            // MessageBox.Show(resultstring);
            try
            {
                jo = (JObject)JsonConvert.DeserializeObject(resultstring);
            }
            catch
            {

            }

            return jo;

        }



        private string CreateToken(string message, string secret)
        {
            string token=BitConverter.ToString(hmacSHA256(message, secret)).Replace("-", "").ToLower();

            return token;
        }


        static byte[] hmacSHA256(String data, String key)
        {
            using (HMACSHA256 hmac = new HMACSHA256(Encoding.ASCII.GetBytes(key)))
            {
                return hmac.ComputeHash(Encoding.ASCII.GetBytes(data));
            }
        }

        public bool test(string resturant_id,string secret)
        {
            bool flag = false;
           
            string time = getTimeStamp();

            string str = "restaurant_id_" + resturant_id + "_" + time;

            string signature = CreateToken(str, secret);

            string url = main_url + "/api/printer/foods?restaurant_id=" + resturant_id + "&signature=" + signature + "&time=" + time;// + currenttimemillis;
            
            JObject jo = getJSON(signature, url);

            if (jo.HasValues)
            {

                string status = jo.GetValue("status").ToString();//.Values.ToString();// HttpGet(url, signature, "");

                if (status.Equals("200"))
                {

                    flag = true;

                }
            }
            return flag;
           
        }


        public bool syncReturant(string resturant_id, string secret, string lang)
        {
            bool flag = false;

            string time = getTimeStamp();

            string str = "restaurant_id_" + resturant_id + "_" + time;

            string signature = CreateToken(str, secret);

            string url = main_url + "/api/printer/restaurant/info?restaurant_id=" + resturant_id + "&time=" + time;// + currenttimemillis;

            JObject jo = getJSON(signature, url);
            
            if (jo.HasValues)
            {
                string status = jo.GetValue("status").ToString();//.Values.ToString();// HttpGet(url, signature, "");

                if (status.Equals("200"))
                {
                    // MessageBox.Show(msg);
                    JObject jo1 = (JObject)JsonConvert.DeserializeObject(jo.GetValue("data").ToString());

                    string name_ug=jo1.GetValue("name_ug").ToString();
                    string name_zh = jo1.GetValue("name_zh").ToString();
                    string out_order_title_ug = jo1.GetValue("out_order_title_ug").ToString();
                    string out_order_title_zh = jo1.GetValue("out_order_title_zh").ToString();
                    string address_ug = jo1.GetValue("address_ug").ToString();
                    string address_zh = jo1.GetValue("address_zh").ToString();
                    string phone = jo1.GetValue("phone").ToString();


                    string sql = "";

                    sql = "update sys_config set value='" + name_ug + "',lang='" + lang + "' where name='resturant_name';";

                    sql += "update sys_config set value='',lang='" + lang + "' where name='tag';";
                    
                    sql += "update sys_config set value='" + address_ug + "',lang='" + lang + "' where name='address';";
                    
                    sql += "update sys_config set value='" + phone + "',lang='" + lang + "' where name='tel';";
                    
                    sql += "update sys_config set value='',lang='" + lang + "' where name='open_time';";
                    
                    sql += "update sys_config set value='',lang='" + lang + "' where name='close_time';";
                   
                    sql += "update sys_config set value='" + resturant_id + "',lang='" + lang + "' where name='restuarant_id';";
                    
                    sql += "update sys_config set value='" + secret + "',lang='" + lang + "' where name='restuarant_key';";
                   
                   // sql += "update sys_config set value='" + order_interval + "',lang='" + lang + "' where name='order_interval';";
                    sql += "update sys_config set value='" + out_order_title_ug + "',lang='" + lang + "' where name='platform_name';";
                    
                    SQLiteHelper SQ = new SQLiteHelper();

                    SQ.update(sql);

                    flag = true;
                }
            }
            return flag;
        }


        public string syncFood(string lang)
        {
            string info = "";

            string url ="";

            string time =getTimeStamp();

            string str = "restaurant_id_" + resturant_id + "_" + time;

            secret = sqlite.getValue("select value from sys_config where name='restuarant_key' ", "value");

            string signature = CreateToken(str, secret);

            url = main_url + "/api/printer/foods?restaurant_id=" + resturant_id + "&time=" +  time;
           
            JObject jo = getJSON(signature, url);

            if (jo.HasValues)
            {
                string status = jo.GetValue("status").ToString();//.Values.ToString();// HttpGet(url, signature, "");

                if (status.Equals("200"))
                {
                    string msg = jo.GetValue("msg").ToString();

                    // MessageBox.Show(msg);
                    JObject jo1 = (JObject)JsonConvert.DeserializeObject(jo.GetValue("data").ToString());
                    JArray ja = (JArray)JsonConvert.DeserializeObject(jo1.GetValue("foods").ToString());
                    for (int i = 0; i < ja.Count; i++)
                    {
                        string food_id = ja[i]["food_id"].ToString();
                        string printer_id = ja[i]["printer_id"].ToString();
                        string image = ja[i]["image"].ToString();
                        string name_ug = ja[i]["name_ug"].ToString();
                        string name_zh = ja[i]["name_zh"].ToString();
                        string description_ug = ja[i]["description_ug"].ToString();
                        string description_zh = ja[i]["description_zh"].ToString();
                        string price = ja[i]["price"].ToString();
                        string weight = ja[i]["weight"].ToString();
                        string state = ja[i]["state"].ToString();
                        string created_at = ja[i]["created_at"].ToString();
                        string begin_time = ja[i]["begin_time"].ToString();
                        string end_time= ja[i]["end_time"].ToString();

                        string fileName = "";
                        var webClient = new WebClient();
                        if (!string.IsNullOrEmpty(image))
                        {
                            string dir = Environment.CurrentDirectory + "\\img";
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }
                             
                            fileName = dir + "\\" + food_id + image.Substring(image.LastIndexOf("."));

                            if (File.Exists(fileName))
                            {
                                try
                                {
                                    File.Delete(fileName);
                                }
                                catch
                                {

                                }
                            }
                            try
                            {
                                webClient.DownloadFileAsync(new Uri(image), fileName);
                            }
                            catch
                            {

                            }

                          //  fileName=fileName.Replace("\\", "\\\\");
                            // fileName="//img//"+ food_id + image.Substring(image.LastIndexOf("."));


                        }
                        //  Console.WriteLine("Chinese:" + name_zh);
                        
                        insertFood(food_id, name_ug, name_zh, fileName, description_ug, description_zh, price, weight, state, created_at, lang,begin_time,end_time);
                    }
                }

                return info;
            }
            info = "服务器连接失败";
            return info;
        }

        private void insertFood(string id, string name_ug, string name_zh, string image,
                                string description_ug, string description_zh, string price, string weight,
                                string state, string created_at,string lang,string begin_time,string end_time)
        {
            SQLiteHelper s = new SQLiteHelper();
            string sql = "select * from food where id=" + id + " and lang='" + lang + "'  ";
            DataTable dt = s.getData(sql);
            if (!lang.Equals("ug"))
            {
                name_ug = name_zh;
                description_ug = description_zh;
            }
            if (dt.Rows.Count == 0)
            {
                sql = " insert into food (id, name, image, description, price, weight, state, created_at, lang,begin_time,end_time) " +
                      " values (" + id + ",'" + name_ug + "','" + image + "','" + description_ug + "'," + price + "," + weight + "," + state + ",'" + created_at +
                      "','" + lang + "','"+begin_time+"','"+end_time+"')";
                s.insert(sql);
            }
            else
            {
                sql = " update food set name='" + name_ug + "',image='" + image + "'," +
                      " description='" + description_ug + "', price='" + price + "', weight='" + weight + "'" +
                      " , state='" + state + "', created_at='" + created_at + "', lang='" + lang + "',begin_time='"+ begin_time + "',end_time='"+ end_time + "' where id='" + id + "' ";

                s.update(sql);
            }
        }


        public string setFoodState(string foodid,string state,string begin_time,string end_time)
        {
            string info = "";

            string time = getTimeStamp();

            string url = main_url + "/api/printer/foods/set-state?restaurant_id=" + resturant_id + "&time=" + time;// + currenttimemillis;

            string str = "restaurant_id_" + resturant_id + "_" + time;

            secret = sqlite.getValue("select value from sys_config where name='restuarant_key' ", "value");
            

            string signature = CreateToken(str, secret);

            string dt = "begin_time="+begin_time+"&end_time="+end_time+"&state=" + state+"&ids[]="+foodid;

            JObject jo = postJSON(signature, url,dt);

            if (jo.HasValues)
            {
                string status = jo.GetValue("status").ToString();//.Values.ToString();// HttpGet(url, signature, "");
                string msg = jo.GetValue("msg").ToString();

                info = msg;
                return info;
            }
            info = "مۇلازىمېترغا ئۇلىنىش مەغلۇب بولدى";
            return info;
        }




        public string getOrder(string maxorderid, string lang)
        {
            string info = "";

            string time =getTimeStamp();

            string url = main_url + "/api/printer/scan-orders?restaurant_id=" + resturant_id + "&max_order_id=" + maxorderid + "&time=" + time;// + currenttimemillis;

            string str = "restaurant_id_" + resturant_id + "_" + time;

            secret = sqlite.getValue("select value from sys_config where name='restuarant_key' ", "value");

            string signature = CreateToken(str, secret);

            JObject jo = getJSON(signature, url);
             
            if (jo.HasValues)
            {
                string status = jo.GetValue("status").ToString();//.Values.ToString();// HttpGet(url, signature, "");

                if (status.Equals("200"))
                {
                    string msg = jo.GetValue("msg").ToString();

                    // MessageBox.Show(msg);
                    JObject jo1 = (JObject)JsonConvert.DeserializeObject(jo.GetValue("data").ToString());
                    JArray ja = (JArray)JsonConvert.DeserializeObject(jo1.GetValue("orders").ToString());

                    //Console.WriteLine(ja.ToString());
                    for (int i = 0; i < ja.Count; i++)
                    {
                        string id = ja[i]["id"].ToString();
                        string order_number = ja[i]["order_number"].ToString();
                        string table_name_ug = ja[i]["table_name_ug"].ToString();
                        string table_name_zh = ja[i]["table_name_zh"].ToString();
                        string user_id = ja[i]["user_id"].ToString();
                        string user_name = ja[i]["user_name"].ToString();
                        string original_price = ja[i]["original_price"].ToString();
                        string price = ja[i]["price"].ToString();
                        string description = ja[i]["description"].ToString();
                        string status_str = ja[i]["status"].ToString();
                        string created_at = ja[i]["created_at"].ToString();

                        insertOrder(id, order_number, table_name_ug, table_name_zh, user_id, user_name, original_price, price, description, status_str, created_at, lang);

                        JArray ja1 = (JArray)JsonConvert.DeserializeObject(ja[i]["order_detail"].ToString());
                        // Console.WriteLine(ja1.ToString());
                        for (int j = 0; j < ja1.Count; j++)
                        {
                            string detail_id = ja1[j]["id"].ToString();
                            string order_id = ja1[j]["order_id"].ToString();
                            string food_id = ja1[j]["food_id"].ToString();
                            // string food_name_ug = ja1[j]["food_name_ug"].ToString();
                            // string food_name_zh = ja1[j]["food_name_zh"].ToString();
                            string detail_original_price = ja1[j]["original_price"].ToString();
                            string detail_price = ja1[j]["price"].ToString();
                            string number = ja1[j]["number"].ToString();

                            orderDetailsInsert(detail_id, order_id, food_id, detail_original_price, detail_price, number);
                        }
                    }
                }
                return info;
            }
            info = "مۇلازىمېترغا ئۇلىنىش مەغلۇب بولدى";
            return info;
        }


        public string getMoneyData(Dictionary<string, string> dict,DataTable data,string start_date, string end_date)
        {
            string info = "";

            string time = getTimeStamp();

            string url = main_url + "/api/printer/report/food-daily-data?restaurant_id=" + resturant_id + "&time=" + time+"&start_date="+start_date+"&end_date="+end_date;// + currenttimemillis;

            string str = "restaurant_id_" + resturant_id + "_" + time;

            secret = sqlite.getValue("select value from sys_config where name='restuarant_key' ", "value");

            string signature = CreateToken(str, secret);

            JObject jo = getJSON(signature, url);

            if (jo.HasValues)
            {
                string status = jo.GetValue("status").ToString();//.Values.ToString();// HttpGet(url, signature, "");

                if (status.Equals("200"))
                {
                    string msg = jo.GetValue("msg").ToString();

                    // MessageBox.Show(msg);
                    JObject jo1 = (JObject)JsonConvert.DeserializeObject(jo.GetValue("data").ToString());
                    string total_paid_price=jo1.GetValue("total_paid_price").ToString();
                    string total_paid_count = jo1.GetValue("total_paid_count").ToString();
                    string total_canceled_price = jo1.GetValue("total_canceled_price").ToString();
                    string total_canceled_count = jo1.GetValue("total_canceled_count").ToString();

                    dict.Add("total_paid_price", total_paid_price);
                    dict.Add("total_paid_count", total_paid_count);
                    dict.Add("total_canceled_price", total_canceled_price);
                    dict.Add("total_canceled_count", total_canceled_count);

                    JArray ja = (JArray)JsonConvert.DeserializeObject(jo1.GetValue("food_data").ToString());


                    

                      for (int i = 0; i < ja.Count; i++)
                      {
                         
                          string name_ug = ja[i]["name_ug"].ToString();
                          string paid_price = ja[i]["paid_price"].ToString();
                          string paid_count = ja[i]["paid_count"].ToString();
                          string canceled_price = ja[i]["canceled_price"].ToString();
                          string canceled_count = ja[i]["canceled_count"].ToString();

                        DataRow r1=data.NewRow();
                        r1["name_ug"]= name_ug;
                        r1["paid_price"]= paid_price;
                        r1["paid_count"]= paid_count;
                        r1["canceled_price"]= canceled_price;
                        r1["canceled_count"]= canceled_count;
                        data.Rows.Add(r1);

                    }
                }
                return status;
            }
            info = "0";
            return info;
        }



        public string getOrderOut(string maxorderid, string lang)
        {
            string info = "";

            string time = getTimeStamp();

            string  str = "restaurant_id_" + resturant_id + "_" + time;

            secret = sqlite.getValue("select value from sys_config where name='restuarant_key' ", "value");

            string signature = CreateToken(str, secret);

            string url = main_url + "/api/printer/orders?restaurant_id=" + resturant_id + "&max_order_id=" + maxorderid + "&time=" + time;// + currenttimemillis;

            JObject jo = getJSON(signature, url);

            if (jo.HasValues)
            {
                string status = jo.GetValue("status").ToString();//.Values.ToString();// HttpGet(url, signature, "");

                if (status.Equals("200"))
                {
                    string msg = jo.GetValue("msg").ToString();

                    // MessageBox.Show(msg);
                    JObject jo1 = (JObject)JsonConvert.DeserializeObject(jo.GetValue("data").ToString());
                    JArray ja = (JArray)JsonConvert.DeserializeObject(jo1.GetValue("orders").ToString());

                    //Console.WriteLine(ja.ToString());
                    for (int i = 0; i < ja.Count; i++)
                    {
                        string id = ja[i]["id"].ToString();
                        string order_number = ja[i]["order_number"].ToString();
                        string user_id = ja[i]["user_id"].ToString();
                        string receiver_name = ja[i]["receiver_name"].ToString();
                        string receiver_mobile = ja[i]["receiver_mobile"].ToString();
                        string receiver_address_ug = ja[i]["receiver_address_ug"].ToString();
                        string receiver_address_zh = ja[i]["receiver_address_zh"].ToString();

                        string user_name = "";
                        string original_price = ja[i]["original_price"].ToString();
                        string price = ja[i]["price"].ToString();
                        string description = ja[i]["description"].ToString();
                        string status_str = ja[i]["status"].ToString();
                        string created_at = ja[i]["created_at"].ToString();

                        string delivery_fee = ja[i]["shipment"].ToString();

                        string pay_type_name_ug = ja[i]["pay_type_name_ug"].ToString();

                        string pay_type_name_zh = ja[i]["pay_type_name_zh"].ToString();

                        string delivery_time = ja[i]["booking_time"].ToString();

                        string address = "";
                        string pay_type = "";
                        if (lang.Equals("ug"))
                        {
                            address = receiver_address_ug;
                            pay_type = pay_type_name_ug;
                        }
                        else
                        {
                            address = receiver_address_zh;
                            pay_type = pay_type_name_zh;
                        }


                        insertOrderOut(id, order_number, pay_type, user_id, user_name, original_price, price, description,
                                       status_str, created_at, lang, delivery_time, delivery_fee, receiver_name, address, receiver_mobile);

                        JArray ja1 = (JArray)JsonConvert.DeserializeObject(ja[i]["order_detail"].ToString());
                        // Console.WriteLine(ja1.ToString());
                        for (int j = 0; j < ja1.Count; j++)
                        {
                            string detail_id = ja1[j]["id"].ToString();
                            string order_id = ja1[j]["order_id"].ToString();
                            string food_id = ja1[j]["food_id"].ToString();
                            // string food_name_ug = ja1[j]["food_name_ug"].ToString();
                            // string food_name_zh = ja1[j]["food_name_zh"].ToString();
                            string detail_original_price = ja1[j]["original_price"].ToString();
                            string detail_price = ja1[j]["price"].ToString();
                            string number = ja1[j]["number"].ToString();

                            orderOutDetailsInsert(detail_id, order_id, food_id, detail_original_price, detail_price, number);
                        }
                    }
                }

                return info;
            }
            info = "مۇلازىمېترغا ئۇلىنىش مەغلۇب بولدى";
            return info;
        }

        private void insertOrder(string id, string order_number, string table_name_ug, string table_name_zh, string user_id, string user_name,
                                 string original_price, string price, string description, string status, string created_at, string lang)
        {
            
            SQLiteHelper s = new SQLiteHelper();
            string sql = "select * from 'order' where id=" + id;
            DataTable dt = s.getData(sql);
            if (dt.Rows.Count == 0)
            {
                if (!lang.Equals("ug"))
                {
                    table_name_ug = table_name_zh;
                }
                sql = "insert into 'order' (id, order_number, table_name, user_id, user_name, original_price, price, description, status, created_at, lang) values ('"
                      + id + "','" + order_number + "','" + table_name_ug + "','" + user_id + "','" + user_name + "','" + original_price + "','" + price + "','" 
                      + description + "','" + status + "','" + created_at + "','" + lang + "')";

                s.insert(sql);
            }

        }

        private void insertOrderOut(string id, string order_number, string pay_type, string user_id, string user_name, string original_price, string price, string description,
                                    string status, string created_at, string lang, string delivery_time, string delivery_fee, string receiver, string address, string phone)
        {

            SQLiteHelper s = new SQLiteHelper();
            string sql = "select * from 'order_out' where id=" + id;
            DataTable dt = s.getData(sql);
            if (dt.Rows.Count == 0)
            {
                
                sql = "insert into 'order_out' (id, order_number, pay_type, user_id, user_name, original_price, price, description, status, created_at, lang, delivery_time, " + 
                      "delivery_fee, receiver, address, phone) values ('" + id + "','" + order_number + "','" + pay_type + "','" + user_id + "','" + user_name + "','" 
                      + original_price + "','" + price + "','" + description + "','" + status + "','" + created_at + "','" + lang + "','" + delivery_time + "','" 
                      + delivery_fee + "','" + receiver + "','" + address + "','" + phone + "')";

                s.insert(sql);
            }
        }

        private void orderDetailsInsert(string id, string order_id, string food_id, string original_price, string price, string number)
        {
            SQLiteHelper s = new SQLiteHelper();
            string sql = "select * from order_detail where id=" + id;
            DataTable dt = s.getData(sql);
            if (dt.Rows.Count == 0)
            {
                sql = "insert into order_detail (id, order_id, food_id, original_price, price, number,status) values ('" + id + "','" + order_id + "','" + food_id + "','"
                    + original_price + "','" + price + "','" + number + "','2') ";

                s.insert(sql);
            }
        }

        private void orderOutDetailsInsert(string id, string order_id, string food_id, string original_price, string price, string number)
        {
            SQLiteHelper s = new SQLiteHelper();
            string sql = "select * from order_out_detail where id=" + id;
            DataTable dt = s.getData(sql);
            if (dt.Rows.Count == 0)
            {
                sql = "insert into order_out_detail (id, order_id, food_id, original_price, price, number,status) values ('" + id + "','" + order_id + "','" + food_id + "','"
                    + original_price + "','" + price + "','" + number + "','2') ";

                s.insert(sql);
            }
        }

        /// <summary> 
        /// POST请求与获取结果 
        /// </summary> 
        public static string HttpPost(string Url,string signature, string postDataStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postDataStr.Length;
            string retString = "";
            request.Headers["signature"] = signature;
            try
            {
                StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII);
                writer.Write(postDataStr);
                writer.Flush();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string encoding = response.ContentEncoding;
                if (encoding == null || encoding.Length < 1)
                {
                    encoding = "UTF-8"; //默认编码 
                }

                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
                retString = reader.ReadToEnd();
            }
            catch
            {

            }
            return retString;
        }
    }
}
